//    Copyright (C) Kherty.  All rights reserved.
using System.Windows;
using System.Windows.Controls;
using OpenLS.UI;

namespace OpenLS.Spreadsheet.UI
{
    public partial class FindAndReplaceControl 
    {
        private readonly FindAndReplace _findAndReplace ;

        public FindAndReplaceControl(Worksheet worksheet)
        {
            InitializeComponent();
            _findAndReplace = new FindAndReplace(worksheet);
            DataContext = FindAndReplace;
        }
        public FindAndReplaceMode Mode
        {
            get
            {
                if (tabControl.SelectedIndex == 0)
                    return FindAndReplaceMode.Find;
                return FindAndReplaceMode.Replace;
            }
            set
            {
                if (value == FindAndReplaceMode.Find)
                {
                    tabControl.SelectedIndex = 0;
                    combo1.Focus();
                }
                else
                {
                    tabControl.SelectedIndex = 1;
                    ToFind.Focus();
                }
            }
        }
        void tabControlSelectionChanged(object sender, object args)
        {
            if (tabControl.SelectedIndex == 0)
                combo1.Focus();
            else if (tabControl.SelectedIndex == 1)
                ToFind.Focus();
        }
        FindAndReplace FindAndReplace { get { return _findAndReplace; } }

        private void combo1_Loaded(object sender, RoutedEventArgs e)
        {
            ((ComboBox) sender).Focus();
        }

        private void OnClose(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
        {
            WindowServices.Close(this, null);

        }

    }
}